#include "as_client.h"
#include "as_session.h"



as::net::TcpClient::TcpClient(asio::io_context &io, const char *addr, int port)
	:io_(io)
{
	asio::ip::tcp::endpoint endpoint(asio::ip::make_address(addr), port);
	addr_ = endpoint;
}

as::net::TcpClient::~TcpClient()
{

}

as::net::TcpClientPtr as::net::TcpClient::Connect(asio::io_context &io, const char *addr, int port)
{
	auto conn = std::make_shared<TcpClient>(io, addr, port);
	conn->Connect();
	return conn;
}

void as::net::TcpClient::Disconnect()
{

}

bool as::net::TcpClient::IsConnect()
{
	if (conn_)
	{
		return conn_->IsConnect();
	}
	return false;
}

void as::net::TcpClient::Connect()
{
	if (conn_)
	{
		conn_->Close();
	}
	else
	{
		conn_ = std::make_shared<Session>(io_);
	}

	conn_->Connect(addr_);
}

